home *** CD-ROM | disk | FTP | other *** search
- Path: hshlab-16.acadiau.ca!005523c
- From: 005523c@axe.acadiau.ca (Christina Chan)
- Newsgroups: comp.lang.c++
- Subject: Help : friend func' for template class
- Date: Thu, 4 Apr 1996 16:18:35 GMT
- Organization: Acadia University
- Message-ID: <005523c.8.3163F65B@axe.acadiau.ca>
- NNTP-Posting-Host: iceberg.acadiau.ca
- X-Newsreader: Trumpet for Windows [Version 1.0 Rev B.7]
-
- Hi,
-
- I am writing a friend function which overload operator<< for a template class
- Bst, but I got a syntax problem, could anybody tell me the right syntax.
-
-
- Declaration : Bst.h
- friend void printTree(ostream& s, (Bst<T>::node*) n);
- friend ostream& operator<< (ostream& s, (Bst<T>&) b);
-
-
- Definition : Bst.cpp
-
- void printTree(ostream& s, Bst<T>::node* n)
- // print a Binary Search Tree in preorder
- {
- if ( n!=NULL )
- {
- printTree(n->lchild);
- s << n->data;
- s << '\n';
- printTree(n->rchild);
- }
- }
-
- ostream& operator<< (ostream& s, Bst<T>& b)
- // Overload operator <<
- {
- printTree(s, b.root);
- return s;
- }
-
-
-